package cn.sskxyz.security.authorization.web.controller;

import cn.sskxyz.mybatis.mode.Page;
import cn.sskxyz.security.authorization.model.SecurityScope;
import cn.sskxyz.security.authorization.service.SecurityScopeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Controller
public class SecurityScopeController {

    @Autowired
    private SecurityScopeService securityScopeService;

    /**
     * 添加scope
     * @param securityScope
     * @return
     */
    @PostMapping("/scope")
    public ResponseEntity addSecurityScope(@RequestBody SecurityScope securityScope) {
        securityScopeService.addSecurityScope(securityScope);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询所有scope列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/scope")
    public ResponseEntity<Page<List<SecurityScope>>> getSecurityScopeList(int currentPage, int pageSize) {
        Page<List<SecurityScope>> scopes = securityScopeService.querySecurityScopeList(currentPage, pageSize);
        return ResponseEntity.ok(scopes);
    }

    /**
     * 更改scope信息和状态
     * @param securityScope
     * @return
     */
    @PutMapping("/scope")
    public ResponseEntity changeSecurityScope(@RequestBody SecurityScope securityScope) {
        securityScopeService.changeSecurityScope(securityScope);
        return ResponseEntity.ok().build();
    }
}
